﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Win.Editors;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Model;
using DevExpress.XtraEditors;

namespace SpeedSCM.Module.Win
{
    [PropertyEditor(typeof(string), false)]
    public class ActionsWinPropertyEditor : StringPropertyEditor, IComplexPropertyEditor
    {
        public ActionsWinPropertyEditor(Type objectType, IModelMemberViewItem model)
            : base(objectType, model)
        {

        }
        protected override object CreateControlCore()
        {
            StringBuilder sb = new StringBuilder();
            if (_application != null)
            {
                foreach (var item in _application.Model.ActionDesign.Actions)
                {
                    sb.Append(item.Id).Append(";");
                }
                base.Model.PredefinedValues = sb.ToString().TrimEnd(';');
            }
            return base.CreateControlCore();
        }
        private XafApplication _application;
        public void Setup(DevExpress.ExpressApp.IObjectSpace objectSpace, DevExpress.ExpressApp.XafApplication application)
        {
            if (_application == null)
            {
                _application = application;
            }
        }
    }
}
